{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# General manipulation of a local csv file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this notebook we will learn how to access a local CSV file, create a dataframe from the CSV file contents, and finally perform some calculations on the data. \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-02-12T22:53:34.101058Z",
     "start_time": "2021-02-12T22:53:34.080144Z"
    }
   },
   "outputs": [],
   "source": [
    "!pip install -r requirements.txt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Imports\n",
    "We will need to import various packages. They are either built in the notebook image you are running, or have been installed in the previous step."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#========================================================================================\n",
    "# import needed libraries/packages\n",
    "#========================================================================================\n",
    "import os\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#========================================================================================\n",
    "# Read the CSV file data into a dataframe\n",
    "#========================================================================================\n",
    "local_dest_dir  = os.path.join(os.getcwd(), 'datasets/')\n",
    "file_name       = 'newtruckdata.csv'\n",
    "getFile         = local_dest_dir + file_name\n",
    "\n",
    "df              = pd.read_csv(getFile)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#========================================================================================\n",
    "# Print the contents of the dataframe\n",
    "# You should see 3 columns:  date, trucktype, mileage\n",
    "#========================================================================================\n",
    "print(df)\n",
    "print(df.mileage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#========================================================================================\n",
    "# Perform calculations (total mileage, total rows of data, average mileage) on data\n",
    "#========================================================================================\n",
    "total_mileage   = sum(df.mileage)  #or total_mileage = dset['mileage'].sum()\n",
    "print(total_mileage)\n",
    "\n",
    "total_rows      = len(df.index)\n",
    "print(total_rows)\n",
    "\n",
    "average_mileage = (total_mileage/total_rows)\n",
    "print(average_mileage)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Congratulations!**  You have used a Jupyter Notebook to analyze a small dataset and gleam meaningful insights :)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
